package dao.mysql;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import beans.Docente;
import conexion.BDConexion;
import dao.interfaces.DocenteDAO;

public class MySqlDocenteDAO implements DocenteDAO {

	@Override
	public List<Docente> listarDocentesBuscarFiltro(String esp) {
		List<Docente> lista = new ArrayList<Docente>();
		Connection cn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			System.out.println(esp);
			esp = esp.isEmpty()?null:esp;
			System.out.println(esp);
			cn = new BDConexion().obtenerConexion();
			String sql = "SELECT * FROM bd_inictel_dcc.docente where esp_doc like concat('%',ifnull(?,''),'%') and estado_doc = 3;";
			pst = cn.prepareStatement(sql);
			pst.setString(1, esp);
			rs = pst.executeQuery();
			while (rs.next()) {
				Docente c = new Docente(rs.getString(1), rs.getString(2),
						rs.getString(3), rs.getString(4), rs.getString(5),
						rs.getInt(6));
				lista.add(c);
			}
		} catch (Exception e) {

		} finally {
			try {
				if (cn != null) {
					cn.close();
				}
				if (pst != null) {
					pst.close();
				}
				if (rs != null) {
					rs.close();
				}
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		return lista;
	}

	@Override
	public List<Docente> listarDocentesBuscar() {
		List<Docente> lista = new ArrayList<Docente>();
		Connection cn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			cn = new BDConexion().obtenerConexion();
			String sql = "SELECT * FROM bd_inictel_dcc.docente where estado_doc = 3;";
			pst = cn.prepareStatement(sql);
			rs = pst.executeQuery();
			while (rs.next()) {
				Docente c = new Docente(rs.getString(1), rs.getString(2),
						rs.getString(3), rs.getString(4), rs.getString(5),
						rs.getInt(6));
				lista.add(c);
			}
		} catch (Exception e) {

		} finally {
			try {
				if (cn != null) {
					cn.close();
				}
				if (pst != null) {
					pst.close();
				}
				if (rs != null) {
					rs.close();
				}
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		return lista;
	}

}
